package test;

import java.io.*;
import java.net.Socket;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

//将product.obj文件通过tcp协议上传到服务端
public class Client {

    public static void main(String[] args) {

        // 替换为实际的服务端地址和端口
        String serverAddress = "127.0.0.1";
        int serverPort = 8080;

        File file = new File("demo24\\src\\test\\product.obj");

        try(
                Socket socket = new Socket(serverAddress, serverPort);
                OutputStream outputStream = socket.getOutputStream();
                FileInputStream fileInputStream = new FileInputStream(file);
                InputStream inputStream = socket.getInputStream();
        ){
            byte[] buf = new byte[1024];
            int len;
            while ((len = fileInputStream.read(buf)) != -1) {
                outputStream.write(buf, 0, len);
            }
            socket.shutdownOutput();

            byte [] buf2 = new byte[1024];
            int len2;
            while ((len2 = inputStream.read(buf2)) != -1) {
                System.out.println(new String(buf2, 0, len2));
            }


        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
